package bb.lanxing.lib.devices.core.ble;

import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCallback;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import bb.lanxing.lib.devices.core.ble.AbsBleDevice;

public class BaseBluetoothGattCallback<CLIENT extends AbsBleDevice> extends BluetoothGattCallback {
    protected final CLIENT mClientRef;

    @Override
    public void onCharacteristicChanged(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic) {
    }

    public BaseBluetoothGattCallback(CLIENT client) {
        this.mClientRef = client;
    }

    @Override
    public final void onConnectionStateChange(BluetoothGatt bluetoothGatt, int i, int i2) {
        CLIENT client = this.mClientRef;
        if (client != null) {
            try {
                client.syncState(i, i2);
            } catch (Exception e) {
                this.mClientRef.e(e);
            }
        }
    }

    @Override
    public final void onServicesDiscovered(BluetoothGatt bluetoothGatt, int i) {
        CLIENT client = this.mClientRef;
        if (client != null) {
            try {
                client.handleServicesDiscovered(i);
            } catch (Exception e) {
                this.mClientRef.e(e);
            }
        }
    }

    @Override
    public void onDescriptorWrite(BluetoothGatt bluetoothGatt, BluetoothGattDescriptor bluetoothGattDescriptor, int i) {
        CLIENT client = this.mClientRef;
        if (client != null) {
            client.notifyRequestResult(i);
        }
    }

    @Override
    public void onDescriptorRead(BluetoothGatt bluetoothGatt, BluetoothGattDescriptor bluetoothGattDescriptor, int i) {
        CLIENT client = this.mClientRef;
        if (client != null) {
            client.notifyRequestResult(i);
        }
    }

    @Override
    public void onCharacteristicWrite(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, int i) {
        CLIENT client = this.mClientRef;
        if (client != null) {
            client.notifyRequestResult(i);
        }
    }

    @Override
    public void onCharacteristicRead(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, int i) {
        CLIENT client = this.mClientRef;
        if (client != null) {
            client.notifyRequestResult(i);
        }
    }

    @Override
    public void onMtuChanged(BluetoothGatt bluetoothGatt, int i, int i2) {
        CLIENT client = this.mClientRef;
        if (client != null) {
            client.handleMtuRequest(i2, i);
        }
    }
}
